/**
 *	会员管理
 *
 *	@auth liangpingzheng
 *	@date 2018-07-17
 */
layui.use(['func', 'form'], function () {
    var form = layui.form,
            func = layui.func,
            $ = layui.$;

    if (a == 'index') {

        //【TABLE列数组】
        var cols = [
            {type: 'checkbox', fixed: 'left'}
            , {field: 'id', width: 80, title: 'ID', align: 'center', sort: true, fixed: 'left'}
            , {field: 'email', width: 200, title: '邮箱', align: 'center'}
            , {field: 'realname', width: 150, title: '会员名称', align: 'center'}
            , {field: 'sex', width: 80, title: '性别', align: 'center', templet: function (d) {
                    var str = "";
                    if (d.sex == 0) {
                        str = '<span class="layui-btn layui-btn-normal layui-btn-xs">保密</span>';
                    } else if (d.sex == 1) {
                        str = '<span class="layui-btn layui-btn-danger layui-btn-xs">男</span>';
                    } else if (d.sex == 2) {
                        str = '<span class="layui-btn layui-btn-warm layui-btn-xs">女</span>';
                    }
                    return str;
                }}
            , {field: 'mobile', width: 130, title: '手机号码', align: 'center'}
            , {field: 'logintime', width: 170, title: '最后登录', align: 'center'}
            , {field: 'regstatus', width: 100, title: '资料完善度', align: 'center', templet: function (d) {
                    var str = "";
                    if (d.regstatus == 1) {
                        str = '<span class="layui-btn layui-btn-normal layui-btn-xs">是</span>';
                    } else if (d.regstatus == 0) {
                        str = '<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-danger">否</span>';
                    }
                    return str;
                }}
            , {field: 'loginnum', width: 90, title: '登录次数', align: 'center'}
            , {field: 'point', width: 80, title: '积分', align: 'center'}
            , {field: 'price', width: 80, title: '余额', align: 'center'}

            , {field: 'status', width: 100, title: '状态', align: 'center', templet: "#statusTpl"}
//            , {field: 'format_add_time', width: 180, title: '注册时间', align: 'center'}
//            , {field: 'format_upd_time', width: 180, title: '更新时间', align: 'center'}
            , {fixed: 'right', width: 220, title: '功能操作区', align: 'center', toolbar: '#toolBar'}
        ];

        //【TABLE渲染】
        func.tableIns(cols, "tableList", function (layEvent, data) {
            if (layEvent === 'price') {
                layer.msg('初始化密码操作');
                var index = layui.layer.open({
                    title: "会员充值",
                    type: 2,
                    content: cUrl + "/price/?id=" + data.id,
                    area: ["500px", "400px"],
                    success: function (layero, index) {
                        //TODO...
                        setTimeout(function () {
                            layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        }, 500)
                    }
                });

            }
        });
        //【设置弹框】
        func.setWin("会员", 870, 520);
        //【状态开关】
        form.on('switch(status)', function (obj) {
            //提示
            layer.tips('温馨提示：关闭后将不在客户终端显示', obj.othis)
            var is_enabled = this.checked ? '1' : '2';

            $.ajax({
                url: cUrl + "/setstatus",
                dataType: "json",
                type: "POST",
                data: {"id": this.value, "status": is_enabled},
                beforeSend: function () {
                    layer.msg('处理中。。。', {
                        icon: 16
                        , shade: 0.01
                        , time: 0
                    });
                },
                success: function (res) {
                    if (res.success) {
                        //2秒后关闭
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });

        });
    }//endif
});